package com.invengo.testrfid.app.dao;

import com.invengo.testrfid.app.dao.base.BaseOperate;

import java.util.List;

public class RfidCageQuery extends BaseOperate {


    private RfidCageBindDao rfidCageBindDao;

    public RfidCageQuery(RfidCageBindDao rfidCageBindDao) {
        this.rfidCageBindDao = rfidCageBindDao;
    }

    @Override
    public void insert(Object object) {

        rfidCageBindDao.insert((RfidCageBind) object);
    }

    @Override
    public void insertAll(List entities) {

    }

    @Override
    public void delete(Object object) {

        rfidCageBindDao.delete((RfidCageBind) object);
    }

    @Override
    public void deleteAll(List objects) {

    }

    @Override
    public void update(Object object) {

        rfidCageBindDao.update((RfidCageBind) object);
    }

    @Override
    public void updateAll(List objects) {

    }

    public RfidCageBind queryDataByTid(String tid) {

        List<RfidCageBind> list = rfidCageBindDao.queryBuilder().where(RfidCageBindDao.Properties.TagId.like("%" + tid + "%")).list();
        if (list.size() > 0) {

            return list.get(0);
        } else {
            return null;
        }
    }

    public RfidCageBind queryDataByCageNo(String cageNo) {

        List<RfidCageBind> list = rfidCageBindDao.queryBuilder().where(RfidCageBindDao.Properties.CageId.eq(cageNo)).list();
        if (list.size() > 0) {

            return list.get(0);
        } else {
            return null;
        }
    }

    public List<RfidCageBind> queryDataByCageByCondition(String cageNo) {

        List<RfidCageBind> list = rfidCageBindDao.queryBuilder().where(RfidCageBindDao.Properties.CageId.like("%" + cageNo + "%")).list();
        return list;
    }


    public RfidCageBind queryDataNoBind() {

        List<RfidCageBind> list = rfidCageBindDao.queryBuilder().where(RfidCageBindDao.Properties.IsBind.eq(false)).list();
        if (list.size() > 0) {

            return list.get(0);
        } else {
            return null;
        }
    }

    public RfidCageBind queryDataNoBind(int skip) {

        List<RfidCageBind> list = rfidCageBindDao.queryBuilder().offset(skip).limit(1).list();
        if (list.size() > 0) {

            return list.get(0);
        } else {
            return null;
        }
    }

    public RfidCageBind queryDataNoBind2(int skip) {

        List<RfidCageBind> list = rfidCageBindDao.queryBuilder().offset(skip).limit(1)
                .where(RfidCageBindDao.Properties.IsBind.eq(false)).list();
        if (list.size() > 0) {

            return list.get(0);
        } else {
            return null;
        }
    }


    public long queryDataNoBindSize() {

        List<RfidCageBind> list = rfidCageBindDao.queryBuilder().where(RfidCageBindDao.Properties.IsBind.eq(false)).list();
        return list.size();
    }


    /**
     * 加载所有的数据
     *
     * @return
     */
    public List<RfidCageBind> loadAllData() {

        return rfidCageBindDao.loadAll();
    }
}
